﻿Public Class Deducciones 
    Public Sub Mostrar()
        If guardar.Enabled = False Then
            guardar.Enabled = True
            cancelar.Enabled = True
            agregar.Enabled = False
            modificar.Enabled = False
            eliminar.Enabled = False
            imprimir.Enabled = False
            PanelArriba.Enabled = True
            PanelAbajo.Enabled = False
        Else
            cancelar.Enabled = False
            guardar.Enabled = False
            agregar.Enabled = True
            Modificar.Enabled = True
            Eliminar.Enabled = True
            imprimir.Enabled = True
            PanelArriba.Enabled = False
            PanelAbajo.Enabled = True

        End If
    End Sub

    Private Sub EmpleadosdeduccionBindingNavigatorSaveItem_Click(sender As System.Object, e As System.EventArgs)
        Me.Validate()
        Me.EmpleadosdeduccionBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.DbFireAndIceDataSet)

    End Sub


    Private Sub EmpleadosdeduccionBindingNavigatorSaveItem_Click_1(sender As System.Object, e As System.EventArgs) Handles EmpleadosdeduccionBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.EmpleadosdeduccionBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.DbFireAndIceDataSet)

    End Sub

    Private Sub Deducciones_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'DbFireAndIceDataSet.deduccionescategoria' table. You can move, or remove it, as needed.
        Me.DeduccionescategoriaTableAdapter.Fill(Me.DbFireAndIceDataSet.deduccionescategoria)
        'TODO: This line of code loads data into the 'DbFireAndIceDataSet.empleados' table. You can move, or remove it, as needed.
        Me.EmpleadosTableAdapter.Fill(Me.DbFireAndIceDataSet.empleados)
        'TODO: This line of code loads data into the 'DbFireAndIceDataSet.empleadosdeduccion' table. You can move, or remove it, as needed.
        Me.EmpleadosdeduccionTableAdapter.Fill(Me.DbFireAndIceDataSet.empleadosdeduccion)

    End Sub

    Private Sub GridControl1_Click(sender As System.Object, e As System.EventArgs) Handles GridControl1.Click

    End Sub

    Private Sub agregar_Click(sender As System.Object, e As System.EventArgs) Handles agregar.Click
        BindingNavigatorAddNewItem.PerformClick()
        Mostrar()
    End Sub

    Private Sub modificar_Click(sender As System.Object, e As System.EventArgs) Handles modificar.Click
        Mostrar()
    End Sub

    Private Sub guardar_Click(sender As System.Object, e As System.EventArgs) Handles guardar.Click
        If IdempleadoGridLookUpEdit.Text.Length = 0 Then
            ErrorProvider1.SetError(IddeduccionescatGridLookUpEdit, "Debe ingresar un Empleado")
        Else
            ErrorProvider1.SetError(IdempleadoGridLookUpEdit, Nothing)

            If DescripcionTextBox.Text.Length = 0 Then
                ErrorProvider1.SetError(DescripcionTextBox, "Debe ingresar una descripción")
                IddeduccionescatGridLookUpEdit.Enabled = False

            Else
                IddeduccionescatGridLookUpEdit.Enabled = True
                ErrorProvider1.SetError(DescripcionTextBox, Nothing)
                EmpleadosdeduccionBindingNavigatorSaveItem.PerformClick()
                MessageBox.Show("Se guardó el resgistro satisfactoriamente")
                Mostrar()
            End If
        End If
    End Sub

    Private Sub cancelar_Click(sender As System.Object, e As System.EventArgs) Handles cancelar.Click
        ErrorProvider1.SetError(DescripcionTextBox, Nothing)
        ErrorProvider1.SetError(IdempleadoGridLookUpEdit, Nothing)
        Mostrar()
        Me.EmpleadosdeduccionTableAdapter.Fill(Me.DbFireAndIceDataSet.empleadosdeduccion)
    End Sub

    Private Sub imprimir_Click(sender As System.Object, e As System.EventArgs) Handles imprimir.Click
        GridControl1.ShowPrintPreview()
    End Sub

    Private Sub eliminar_Click(sender As System.Object, e As System.EventArgs) Handles eliminar.Click
        Dim opcion As Integer
        opcion = MsgBox("¿Está seguro que desea eliminar el registro?", MsgBoxStyle.YesNo + MsgBoxStyle.Question, "Eliminar registro")
        If opcion = vbYes Then
            Try
                EmpleadosdeduccionTableAdapter.DeleteDeduccionQuery(IddeduccionTextBox.Text)
                Me.EmpleadosdeduccionTableAdapter.Fill(Me.DbFireAndIceDataSet.empleadosdeduccion)
            Catch ex As Exception
                MsgBox("Lo sentimos, el registro no puede ser eliminado ya que está relacionado con otras tablas", MsgBoxStyle.Critical, "Error")
            End Try


        End If
    End Sub

    Private Sub IdempleadoGridLookUpEdit_EditValueChanged(sender As System.Object, e As System.EventArgs) Handles IdempleadoGridLookUpEdit.EditValueChanged

    End Sub
End Class